package net.minecraft.src;

import java.util.Random;

public class PPHGenCordaites extends WorldGenerator
{

    public PPHGenCordaites()
    {
    }

    public boolean generate(World world, Random random, int i, int j, int k)
    {
	if(world.getBlockId(i, j - 1, k) == mod_pph.prehistoricGrass.blockID && world.isAirBlock(i, j + 10, k) && j < 85)
	{
	for(int width = -4; width < 5; width++)
	{
		for(int height = 0; height < 40; height++)
		{
			for(int depth = -4; depth < 5; depth++)
			{
				for(int width2 = 0; width2 < 1; width2++)
				{
					for(int height2 = 0; height2 < 28 + random.nextInt(6); height2++)
					{
						for(int depth2 = 0; depth2 < 1; depth2++)
						{
							world.setBlockAndMetadata(i+width2, j+height2, k+depth2, mod_pph.prehistoricWood.blockID, 2);
						}
					}
				}
				if(world.getBlockId(i+width, j+height-1, k+depth) == mod_pph.prehistoricWood.blockID && world.isAirBlock(i+width, j+height, k+depth))
				{
				for(int width2 = -2; width2 < 3; width2++)
				{
					for(int height2 = -2; height2 < 3; height2++)
					{
						for(int depth2 = -2; depth2 < 3; depth2++)
						{
						int l = (int)Math.round(Math.sqrt(Math.pow(width2,2) + Math.pow(height2,2) + Math.pow(depth2,2)));
						if(l <= 2 && world.isAirBlock(i+width+width2, j+height+height2, k+depth+depth2))
						{
							world.setBlockAndMetadata(i+width+width2, j+height+height2, k+depth+depth2, mod_pph.prehistoricLeaves.blockID, 2);
						}
						}
					}
				}
				}
					generateBranches(world, random, i+width, j+height, k+depth, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0);
					generateBranches(world, random, i+width, j+height, k+depth, -1, -2, -3, -4, -5, 0, 0, 0, 0, 0);
					generateBranches(world, random, i+width, j+height, k+depth, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5);
					generateBranches(world, random, i+width, j+height, k+depth, 0, 0, 0, 0, 0, -1, -2, -3, -4, -5);
					generateBranches(world, random, i+width, j+height, k+depth, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5);
					generateBranches(world, random, i+width, j+height, k+depth, -1, -2, -3, -4, -5, 1, 2, 3, 4, 5);
					generateBranches(world, random, i+width, j+height, k+depth, 1, 2, 3, 4, 5, -1, -2, -3, -4, -5);
					generateBranches(world, random, i+width, j+height, k+depth, -1, -2, -3, -4, -5, -1, -2, -3, -4, -5);
			}
		}
	}
	}
		return true;
	}
	
	
	private boolean generateBranches(World world, Random random, int i, int j, int k, int i1, int i2, int i3, int i4, int i5, int k1, int k2, int k3, int k4, int k5)
	{
	if(world.isAirBlock(i, j, k) && world.getBlockId(i - i1, j - 1, k - k1) == mod_pph.prehistoricWood.blockID && world.getBlockMetadata(i - i1, j - 1, k - k1) == 2)
	{
	if(random.nextInt(10) == 0)
	{
		world.setBlockAndMetadata(i, j, k, mod_pph.prehistoricWood.blockID, 2);
		world.setBlockAndMetadata(i + i1, j + 1, k + k1, mod_pph.prehistoricWood.blockID, 2);
		world.setBlockAndMetadata(i + i2, j + 2, k + k2, mod_pph.prehistoricWood.blockID, 2);
		world.setBlockAndMetadata(i + i3, j + 3, k + k3, mod_pph.prehistoricWood.blockID, 2);
		world.setBlockAndMetadata(i + i4, j + 4, k + k4, mod_pph.prehistoricWood.blockID, 2);
		world.setBlockAndMetadata(i + i5, j + 5, k + k5, mod_pph.prehistoricWood.blockID, 2);
		for(int width = -2; width < 3; width++)
		{
			for(int height = -2; height < 3; height++)
			{
				for(int depth = -2; depth < 3; depth++)
				{
				int l = (int)Math.round(Math.sqrt(Math.pow(width,2) + Math.pow(height,2) + Math.pow(depth,2)));
				int l1 = i + i5;
				int l2 = j + 5;
				int l3 = k + k5;
				if(l <= 2 && world.isAirBlock(l1+width, l2+height, l3+depth))
				{
					world.setBlockAndMetadata(l1+width, l2+height, l3+depth, mod_pph.prehistoricLeaves.blockID, 2);
				}
				}
			}
		}
		}
		}
		return true;
	}
}